** Table 2: ECB access
clear

** Loading data
*Include:
*cd // *Your directory path goes here* //
import excel .\Data\GC_DailyAverages_Pseudo.xlsx, firstrow allstring

* Step 1: Organize the data:
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
drop refdate
gen year = year(dateSTATA)
gen month = month(dateSTATA)

destring volweightedrate volsum ecbaccesslender, replace
encode basket, gen(basketcat)
drop basket
label define order  1 ON  2 TN  3 SN
encode term, gen(termcat) label(order)
drop term

gen QE = 0
*start of QE, see: https://www.ecb.europa.eu/mopo/implement/app/html/index.en.html#pspp
replace QE = 1 if dateSTATA > date("08.03.2015","DMY") 

egen panelid = group(basketcat termcat ecbaccesslender)
xtset panelid dateSTATA

* Step 2: Add information on EONIA
* download daily data from, for example, Bloomberg / Thomson Reuters and replace code below:
gen EONIA=0.5 // create pseudodata

* Step 3: Add information on DFR
* download data on the DFR (see: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/key_ecb_interest_rates/html/index.en.html) and replace code below:
gen DFR=0.5 // create pseudodata

* Step 4: Calculate daily, average GC rate
preserve
sort country dateSTATA
by country dateSTATA: egen meanGCRate = wtmean(volweightedrate), weight(volsum)
keep meanGCRate country dateSTATA
duplicates drop
save .\Data\MeanGCRatesByCountry.dta, replace
restore
merge m:1 dateSTATA country using .\Data\MeanGCRatesByCountry.dta
keep if _merge==3
drop _merge
erase .\Data\MeanGCRatesByCountry.dta

gen GCBelowDep = 0
replace GCBelowDep = 1 if meanGCRate<DFR

* Step 5: Calculate changes:
bysort panelid (dateSTATA): gen delrGC = log(volweightedrate[_n]/volweightedrate[_n-1])
bysort panelid (dateSTATA): gen delrGCtm1 = log(volweightedrate[_n-1]/volweightedrate[_n-2])
bysort panelid (dateSTATA): gen delMMRate = log(EONIA[_n]/EONIA[_n-1])

* Step 6: Calculate additional regression inputs:
gen delMMRate_GCBelowDep = delMMRate*GCBelowDep
gen delMMRate_Acc = delMMRate*ecbaccesslender
gen delMMRate_Acc_BelGC = delMMRate*ecbaccesslender*GCBelowDep

** Regressions

* All
eststo clear
sort termcat
eststo R3a, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R3b, title("ON/TN"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R3c, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep ecbaccesslender delMMRate_Acc delMMRate_Acc_BelGC delrGCtm1, absorb(year##month##termcat) vce(robust) nocons

* Core
keep if (country=="DE"|country=="FR"|country=="BE"|country=="NL"|country=="FI"|country=="AT")
sort termcat
eststo R2a, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R2b, title("ON/TN"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R2c, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep ecbaccesslender delMMRate_Acc delMMRate_Acc_BelGC delrGCtm1, absorb(year##month##termcat) vce(robust) nocons

* Germany
keep if (country=="DE")
sort termcat
eststo R1a, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R1b, title("ON/TN"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R1c, title("ON/TN"): reghdfe delrGC delMMRate GCBelowDep delMMRate_GCBelowDep ecbaccesslender delMMRate_Acc delMMRate_Acc_BelGC delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
